
#ifndef BNETLOGGER_H
#define BNETLOGGER_H

#include <qthread.h>
#include <qobject.h>
#include <qmutex.h>
#include <qfile.h>

#include "BnetMessage.h"
#include "PacketSniffer.h"

class BnetLogger : public QObject, public QThread
{
Q_OBJECT
public:
    BnetLogger( QObject* parent = 0,
		const char* name = 0 );
    ~BnetLogger();
 

    bool setLogging( const bool& logging );
    bool setLoggingToFile( const bool& loggingToFile,
			   const QString& filename = "",
			   const bool& logUserInChannelEnabled = true,
			   const bool& logUserJoinLeaveEnabled = true );

    bool isLogging();
    bool isLoggingToFile();
    
    QString getFilename();
    QString timestampStr();  // Timestamp in the form "[M/d hh:mm:ss] ".
 protected:
    void run();
    
signals:
    void logging( BnetMessage );

private:
    // Unimplemented functions.
    BnetLogger( const BnetLogger& );
    BnetLogger& operator=( const BnetLogger& );

    // The current logged in user.
    QString currUser_;

    // Sniffer, which is used to sniff packets.
    PacketSniffer sniffer_;

    // Generic logging; which is just emitting the logging signal.
    QMutex loggingMutex_;
    bool isLogging_;
    
    // Logging-to-file stuff.
    QString filename_;
    QFile logFile_;

    QMutex loggingToFileMutex_;
    bool isLoggingToFile_;
    bool logUserInChannelEnabled_;
    bool logUserJoinLeaveEnabled_;
};


    
#endif
